<#setting number_format="0.###"/>
<#setting date_format="yyyy-MM-dd">
<#macro getObjectFieldValue object name returnValue>
	<#assign dotIndex = name?index_of(".")/>
	<#if dotIndex != -1>
		<#assign fieldList = name?split(".")/>
		<#if !object[fieldList[0]]?exists>
			<#assign tName = name?substring(dotIndex + 1, name?length)/>
			<#assign fieldList = tName?split(".")/>
		</#if>
		<#if object?exists>
			<#assign result = object/>
			<#list fieldList as field>
				<#if result[field]?exists>
					<#assign result = result[field]/>
				<#else>
					<#assign result = ""/>
					<#break/>
				</#if>
			</#list>
			<#if result?exists>
				<#attempt>
					<#if returnValue != 'noReturn'>
						<#assign returnValue=result/>
					<#else>
						<#lt/>${result?string}<#rt/>
					</#if>
				
			<#recover>
				<#attempt>
					<#if returnValue != 'noReturn'>
						<#assign returnValue=result/>
					<#else>
						<#lt/>${result?date}<#rt/>
					</#if>
				<#recover>
				</#attempt>
			</#attempt>
			</#if>
		</#if>
	<#else>
		<#if object[name]?exists>
			<#attempt>
				<#if returnValue != 'noReturn'>
					<#assign value=object[name]/>
				<#else>
					<#lt/>${object[name]?string}<#rt/>
				</#if>
			<#recover>
				<#attempt>
					<#if returnValue != 'noReturn'>
						<#assign value=object[name]/>
					<#else>
						<#lt/>${object[name]?date}<#rt/>
					</#if>
				<#recover>
				</#attempt>
			</#attempt>
		</#if>
	</#if>
</#macro>
<#if parameters.isUseInputPanel>
<div style="float:left;">
	<table>
		<tr>
			<td colspan="2">
				<#if parameters.buttonsHidden?index_of("create") == -1>
					<input class="button" id="_tableeditor_button_create" onclick="tableeditor.onCreateButtonClick();" type="button" value="${parameters.createButtonValue?default(parameters.__i18n__.getText("message.tableeditorCreate"))}"/>
				</#if>
				<#if parameters.buttonsHidden?index_of("update") == -1>
					<input class="button" style="display:none" id="_tableeditor_button_update" onclick="tableeditor.onUpdateButtonClick();" type="button" value="${parameters.updateButtonValue?default(parameters.__i18n__.getText("message.tableeditorUpdate"))}"/>
				</#if>
				<#if parameters.buttonsHidden?index_of("reset") == -1>
					<input class="button" id="_tableeditor_button_reset" onclick="tableeditor.onResetButtonClick(1);" type="button" value="${parameters.resetButtonValue?default(parameters.__i18n__.getText("message.tableeditorReset"))}"/>
				</#if>
				<#if parameters.buttonsHidden?index_of("new") == -1>
					<input class="button" style="display:none" id="_tableeditor_button_new" onclick="tableeditor.onNewButtonClick();" type="button" value="${parameters.newButtonValue?default(parameters.__i18n__.getText("message.tableeditorNew"))}"/>
				</#if>
			</td>
		</tr>
	</table>
</div>
</form>
</div>

</div>
</#if>


<div style="float:left;margin:8px 0px;width:100%;">
	<#if parameters.head?exists>
	<div class="panelHead">
		<div class="panelHeadLeft"></div>
		<div class="panelHeadMiddle">${parameters.head}</div>
		<div class="panelHeadRight"></div>
	</div>
	</#if>
	<table class="panelTable">
		<tr>
			<td>
				<div id="_tableeditor_button_bar">
					<#if parameters.buttonsHidden?index_of("view") == -1>
						<div style="float:left;">
							<input disabled="true" class="buttonDisabled" id="_tableeditor_button_view" onclick="tableeditor.onViewButtonClick();" type="button" value="${parameters.viewButtonValue?default(parameters.__i18n__.getText("message.tableeditorView"))}"/>
						</div>
					</#if>
					<#if parameters.buttonsHidden?index_of("edit") == -1>
						<div style="float:left;margin:0px 0px 0px 4px;">
							<input disabled="true" class="buttonDisabled" id="_tableeditor_button_edit" onclick="tableeditor.onEditButtonClick();" type="button" value="${parameters.editButtonValue?default(parameters.__i18n__.getText("message.tableeditorEdit"))}"/>
						</div>
					</#if>
					<#if parameters.buttonsHidden?index_of("delete") == -1>
						<div style="float:left;margin:0px 0px 0px 4px;">
							<input disabled="true" class="buttonDisabled" id="_tableeditor_button_delete" onclick="tableeditor.onDeleteButtonClick();" type="button" value="${parameters.deleteButtonValue?default(parameters.__i18n__.getText("message.tableeditorDelete"))}"/>
						</div>
					</#if>
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<table id="_tableeditor_dataTable" class="tableeditor_dataTable" cellspacing="0" cellpadding="0">
					<#if parameters.isUseCheckbox>
						<colgroup/>
					</#if>
					<#list tag.columns as column>
						<#if column.parameters.isListDisplay>
							<colgroup <#include "/${parameters.templateDir}/geni/tableeditorcolumn-common.ftl"/>>
							</colgroup>
						</#if>
					</#list>
					<tr>
						<#if parameters.isUseCheckbox>
							<th class="first"><input id="_tableeditor_checkbox" name="_tableeditor_checkbox" type="checkbox" onclick="tableeditor.checkAll(this);"/></th>
						</#if>
					<#list tag.columns as column>
						<#if column.parameters.isListDisplay>
							<th onclick="tableeditor.columnHeadOnClick(this, '${column.parameters.name?default('')}', true);"><a><span class="label">${column.parameters.label?default("")}</span></a></th>
						</#if>
					</#list>
					<#if parameters.changeOrderAction?exists>
						<th class="changeOrder"></th>
					</#if>
					</tr>
				<#assign rownum = 0 />
				<#if parameters.pageSize?exists>
					<tr id="_tableeditor_page_row">
						<td colspan="${tag.columns?size + 1}" align="right" class="page">
						<#include "/${parameters.templateDir}/geni/tableeditor-page.ftl"/>
						</td>
					</tr>
				</#if>
				</table>
			</td>
		</tr>
	</table>
</div>
<#if (tag.childTableColumns?size > 0)>
	<div style="float:left;margin:8px 0px;">
		<#if parameters.childTableHead?exists>
		<div class="panelHead">
			<div class="panelHeadLeft"></div>
			<div class="panelHeadMiddle">${parameters.childTableHead}</div>
			<div class="panelHeadRight"></div>
		</div>
		</#if>
		<table class="panelTable">
			<tr>
				<td>
					<table id="_tableeditor_dataTable2" class="tableeditor_dataTable" cellspacing="0" cellpadding="0">
						<#list tag.childTableColumns as column>
							<colgroup <#include "/${parameters.templateDir}/geni/tableeditorcolumn-common.ftl"/>>
							</colgroup>
						</#list>
						<tr>
							<#list tag.childTableColumns as column>
								<th onclick="tableeditor.childTableColumnHeadOnClick(this, '${column.parameters.name?default('')}', true);"><a><span class="label">${column.parameters.label?default("")}</span></a></th>
							</#list>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</div>
</#if>
<#include "/${parameters.templateDir}/geni/tableeditor-close-validate.ftl" />
<script>
	if(tableeditor == undefined){
		var tableeditor = {};
	}
	tableeditor.id = "${parameters.id}";
	tableeditor.maxRowNum = ${rownum} + 1;
	//record the ID field name of the object in the list.
	tableeditor.IDFieldName = "${parameters.idFieldName}";
	tableeditor.childDataIDFieldName = "${parameters.childDataIDFieldName}";
	
	tableeditor.createUrl = "${parameters.createAction}";
	tableeditor.updateUrl = "${parameters.updateAction}";
	tableeditor.deleteUrl = "${parameters.deleteAction}";
	tableeditor.changeOrderUrl = "${parameters.changeOrderAction?default("null")}";
	tableeditor.getChildTableDataUrl = "${parameters.getChildTableDataAction?default("null")}";
	
	//record the list object as a javascript array.
	tableeditor.list = eval("(${parameters.listJsonData?js_string})");
	
	try{	
		tableeditor.validateCreateFunction = validateForm_${parameters.id}_1;
		tableeditor.validateUpdateFunction = validateForm_${parameters.id}_2;
		tableeditor.validateDeleteFunction = validateForm_${parameters.id}_3;
	}catch(e){}
	tableeditor.totalNum = ${parameters.totalNum?default(0)};
	tableeditor.pageSize = ${parameters.pageSize?default(0)};
	tableeditor.pageNum = ${pageNum?default(1)};
	
	//record all the columns name.
	tableeditor.columns = [];
	tableeditor.columnInnerHTMLs = [];
	//record all the columns name including the one which isListDisplay property is false.
	tableeditor.allColumns = [];
	tableeditor.allColumnDateFormats = [];
	tableeditor.columnTds = [];
	<#list tag.columns as column>
		<#if column.parameters.name?exists>
			tableeditor.allColumns.push("${column.parameters.name}");
			tableeditor.allColumnDateFormats.push("${column.parameters.dateFormat?default('')}");
		</#if>
		<#if column.parameters.isListDisplay>
			tableeditor.columns.push("${column.parameters.name?default('')}");
			tableeditor.columnInnerHTMLs.push("${column.parameters.innerHTML?default('')}");
			var td = document.createElement("TD");
			td.outerHTML = '<td id="_tableeditor_td_column_template" <#include "/${parameters.templateDir}/geni/tableeditorcolumn-common.ftl"/>></td>';
			tableeditor.columnTds.push(td);
		</#if>
	</#list>
	
	//record all the child table columns name.
	tableeditor.childTableColumns = [];
	tableeditor.childTableColumnInnerHTMLs = [];
	tableeditor.childTableColumnDateFormats = [];
	tableeditor.childTableColumnTds = [];
	<#list tag.childTableColumns as column>
		tableeditor.childTableColumns.push("${column.parameters.name?default('')}");
		tableeditor.childTableColumnInnerHTMLs.push("${column.parameters.innerHTML?default('')}");
		tableeditor.childTableColumnDateFormats.push("${column.parameters.dateFormat?default('')}");
		var td = document.createElement("TD");
		td.outerHTML = '<td id="_tableeditor_td_column_template" style="display:none;" <#include "/${parameters.templateDir}/geni/tableeditorChildTableColumn-common.ftl"/>></td>';
		tableeditor.childTableColumnTds.push(td);
	</#list>
	
	tableeditor.updateIndexOutOfRangeMessage = "${parameters.__i18n__.getText("message.tableeditorUpdateIndexOutOfRange")}";
	tableeditor.autoGenerateMessage = "${parameters.__i18n__.getText("message.tableeditorAutoGenerate")}";
	tableeditor.confirmDeleteMessage = "${parameters.__i18n__.getText("message.tableeditorConfirmDelete")}";
	tableeditor.checkItemToEditMessage = "${parameters.__i18n__.getText("message.tableeditorCheckItemToEdit")}";
	tableeditor.checkItemToDeleteMessage = "${parameters.__i18n__.getText("message.tableeditorCheckItemToDelete")}";
	
	if($(tableeditor.id)){
		var idInput = $(tableeditor.id)[tableeditor.IDFieldName];
		if(idInput){
			tableeditor.disableIdInput(true);
			idInput.value=tableeditor.autoGenerateMessage;
		}
	}
	tableeditor.upArrowImgSrc = '<@s.url value='/struts/geni/images/up.gif' includeParams='none' encode='false' />';
	tableeditor.downArrowImgSrc = '<@s.url value='/struts/geni/images/down.gif' includeParams='none' encode='false' />';
	tableeditor.isUseCheckbox = ${parameters.isUseCheckbox?string};	
	
	<#if (actionErrors?exists && actionErrors?size > 0)>
		try{
		<#list actionErrors as error>
			validation.addActionErrors(['${error}'], tableeditor.id);
		</#list>
		}catch(e){}
	</#if>
	<#if (actionMessages?exists && actionMessages?size > 0)>
		try{
		<#list actionMessages as message>
			validation.addActionMessages(['${message}'], tableeditor.id);
		</#list>
		}catch(e){}
	</#if>
	tableeditor.reshowList();
	<#if parameters.isShowDefault>
		tableeditor.showDefaultInEditing();
	</#if>
</script>
